<!-- main -->
<template>
  <div class="main">
    <el-container>
      <el-header>
        <div class="logo">
          <img src="../../assets/logo.png" alt="" />
        </div>
        <div class="name">{{headerUsername}}
          [<a href="javascript:;" @click="goBack">退出登录</a>]
        </div>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-menu
            :default-active="activePath"
            background-color="#fff"
            text-color="#333"
            active-text-color="#f55"
            :unique-opened="true"
            :router="true"
            :collapse="isCollapse"
          >
            <el-submenu
              :index="meunListData.path"
              v-for="meunListData in meunListDatas"
              :key="meunListData.id"
            >
              <template slot="title">
                <i class="el-icon-s-custom"></i>
                <span>{{ meunListData.title }}</span>
              </template>
              <el-menu-item
                :index="meunList.path"
                v-for="meunList in meunListData.children"
                :key="meunList.id"
              >
                <i class="el-icon-shopping-bag-1"></i>
                {{ meunList.title }}
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import {removeToken} from "../../utils/auth.js";
// console.log(getToken());
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      headerUsername:localStorage.getItem("name"),
      activePath: "/admin/users/list",
      isCollapse: false,
      meunListDatas: [
        {
          id: 1,
          title: "用户管理",
          path: "/admin/users/list",
          children: [
            {
              id: 10001,
              path: "/admin/users/list",
              title: "用户列表",
            },
            {
              id: 10002,
              path: "/admin/users/add",
              title: "添加用户",
            },
          ],
        },
        {
          id: 2,
          title: "产品管理",
          path: "/admin/products/list",
          children: [
            {
              id: 20001,
              path: "/admin/products/list",
              title: "产品列表",
            },
            {
              id: 20002,
              path: "/admin/products/add",
              title: "添加产品",
            },
            {
              id: 20003,
              path: "/admin/category/list",
              title: "产品分类",
            }
          ],
        },
      ],
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {
    $route(to) {
      // console.log(to);
      this.activePath=to.path;
    },
  },
  //方法集合
  methods: {
    goUserlist() {
      this.$router.push("/admin/userlist");
    },
    goUseradd() {
      this.$router.push("/admin/useradd");
    },
    goBack(){
      removeToken(this.headerUsername);
      localStorage.removeItem("name");
      this.$router.push("/admin/login");
    }
  },
  mounted() {
      this.activePath=this.$route.path;
      // console.log(this.headerUsername);
  },
};
</script>
<style lang="less">
.main {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  .el-container {
    height: 100%;
    .el-header {
      background: rgba(0, 0, 0, 0.8);
      display:flex;
      justify-content: space-between;
      .logo {
        width: 200px;
        height: 60px;
        float: left;
        color: #fff;
        height: 100%;
        line-height: 60px;
        font-size: 20px;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .name{
          color:#fff;
          height: 60px;
          // width: 5rem;
          line-height: 60px;
        }
    }
    .el-aside {
      background: rgb(240, 240, 240);
    }
  }
    .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #818588;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 50px;
    height: 50px;
    line-height: 50px;
    text-align: center;
  }
  .avatar {
    width: 50px;
    height: 50px;
    display: block;
  }
}
</style>